package cn.ultrarisk.scadmin.manager.biz.solr.entity;

import cn.ultrarisk.scadmin.manager.biz.solr.context.SolrState;
import cn.ultrarisk.mybatis.extension.annotation.Table;

import java.io.Serializable;
import java.util.*;

/**
 * solr集合副本实体类
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/4/14
 * @since V1.0
 */
@Table(table = "solr_replica", idColumn = SolrReplica.ID, autoIncrement = true)
public class SolrReplica implements Serializable {
    private static final long serialVersionUID = -4459171379537832862L;

    public final static String ID = "id";
    public final static String CORE_NAME = "core_name";
    public final static String REPLICA_NAME = "replica_name";
    public final static String STATE = "state";
    public final static String COLLECTION_ID = "collection_id";
    public final static String NODE_ID = "node_id";
    public final static String SHARD_ID = "shard_id";
    public final static String LEADER = "leader";
    public final static String AVAILABLE = "available";
    public final static String SEGMENT_NUM = "segment_num";
    public final static String LAST_MODIFIED = "last_modified";
    public final static String VERSION = "version";
    public final static String INSTANCE_DIR = "instance_dir";
    public final static String DATA_DIR = "data_dir";
    public final static String CONFIG_XML = "config_xml";
    public final static String SCHEMA_XML = "schema_xml";
    public final static String DIRECTORY = "directory";
    public final static String COMMIT_TIME = "commit_time";
    public final static String START_TIME = "start_time";
    public final static String UPTIME = "uptime";
    public final static String UPDATE_TIME = "update_time";

    public static final Map<String, String> COLUMN_PROPERTY_MAP = new LinkedHashMap<String, String>();

    static {
        COLUMN_PROPERTY_MAP.put(ID, "id");
        COLUMN_PROPERTY_MAP.put(CORE_NAME, "coreName");
        COLUMN_PROPERTY_MAP.put(REPLICA_NAME, "replicaName");
        COLUMN_PROPERTY_MAP.put(STATE, "state");
        COLUMN_PROPERTY_MAP.put(COLLECTION_ID, "collectionId");
        COLUMN_PROPERTY_MAP.put(NODE_ID, "nodeId");
        COLUMN_PROPERTY_MAP.put(SHARD_ID, "shardId");
        COLUMN_PROPERTY_MAP.put(LEADER, "leader");
        COLUMN_PROPERTY_MAP.put(AVAILABLE, "available");
        COLUMN_PROPERTY_MAP.put(SEGMENT_NUM, "segmentNum");
        COLUMN_PROPERTY_MAP.put(LAST_MODIFIED, "lastModified");
        COLUMN_PROPERTY_MAP.put(VERSION, "version");
        COLUMN_PROPERTY_MAP.put(INSTANCE_DIR, "instanceDir");
        COLUMN_PROPERTY_MAP.put(DATA_DIR, "dataDir");
        COLUMN_PROPERTY_MAP.put(CONFIG_XML, "configXml");
        COLUMN_PROPERTY_MAP.put(SCHEMA_XML, "schemaXml");
        COLUMN_PROPERTY_MAP.put(DIRECTORY, "directory");
        COLUMN_PROPERTY_MAP.put(START_TIME, "startTime");
        COLUMN_PROPERTY_MAP.put(COMMIT_TIME, "commitTime");
        COLUMN_PROPERTY_MAP.put(UPTIME, "uptime");
        COLUMN_PROPERTY_MAP.put(UPDATE_TIME, "updateTime");
    }

    /**
     * id
     */
    private Integer id;
    /**
     * core名称
     */
    private String coreName;
    /**
     * replica名称
     */
    private String replicaName;
    /**
     * 状态
     */
    private SolrState state;
    /**
     * 集合id
     */
    private Integer collectionId;
    /**
     * 节点id
     */
    private Integer nodeId;
    /**
     * 分片id
     */
    private Integer shardId;
    /**
     * 是否Leader
     */
    private Boolean leader;
    /**
     * 是否有效
     */
    private Boolean available;
    /**
     * 段数量
     */
    private Integer segmentNum;
    /**
     * 最后修改时间
     */
    private Date lastModified;
    /**
     * 版本
     */
    private Integer version;
    /**
     * 实例目录
     */
    private String instanceDir;
    /**
     * 数据目录
     */
    private String dataDir;
    /**
     * config配置
     */
    private String configXml;
    /**
     * schema配置
     */
    private String schemaXml;
    /**
     * directory
     */
    private String directory;
    /**
     * 开始时间
     */
    private Date startTime;
    /**
     * commit时间
     */
    private Long commitTime;
    /**
     * 运行时间
     */
    private Long uptime;
    /**
     * 更新时间
     */
    private Long updateTime;
    /**
     * 缓存
     */
    private List<SolrCache> caches;

    public SolrReplica() {
    }

    public SolrReplica(String coreName, String replicaName, SolrState state, Boolean leader, Integer shardId, Integer collectionId, Integer nodeId) {
        this.coreName = coreName;
        this.replicaName = replicaName;
        this.state = state;
        this.collectionId = collectionId;
        this.nodeId = nodeId;
        this.shardId = shardId;
        this.leader = leader;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCoreName() {
        return coreName;
    }

    public void setCoreName(String coreName) {
        this.coreName = coreName;
    }

    public String getReplicaName() {
        return replicaName;
    }

    public void setReplicaName(String replicaName) {
        this.replicaName = replicaName;
    }

    public SolrState getState() {
        return state;
    }

    public void setState(SolrState state) {
        this.state = state;
    }

    public Integer getCollectionId() {
        return collectionId;
    }

    public void setCollectionId(Integer collectionId) {
        this.collectionId = collectionId;
    }

    public Integer getNodeId() {
        return nodeId;
    }

    public void setNodeId(Integer nodeId) {
        this.nodeId = nodeId;
    }

    public Integer getShardId() {
        return shardId;
    }

    public void setShardId(Integer shardId) {
        this.shardId = shardId;
    }

    public Boolean getLeader() {
        return leader;
    }

    public void setLeader(Boolean leader) {
        this.leader = leader;
    }

    public Boolean getAvailable() {
        return available;
    }

    public void setAvailable(Boolean available) {
        this.available = available;
    }

    public Integer getSegmentNum() {
        return segmentNum;
    }

    public void setSegmentNum(Integer segmentNum) {
        this.segmentNum = segmentNum;
    }

    public Date getLastModified() {
        return lastModified;
    }

    public void setLastModified(Date lastModified) {
        this.lastModified = lastModified;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getInstanceDir() {
        return instanceDir;
    }

    public void setInstanceDir(String instanceDir) {
        this.instanceDir = instanceDir;
    }

    public String getDataDir() {
        return dataDir;
    }

    public void setDataDir(String dataDir) {
        this.dataDir = dataDir;
    }

    public String getConfigXml() {
        return configXml;
    }

    public void setConfigXml(String configXml) {
        this.configXml = configXml;
    }

    public String getSchemaXml() {
        return schemaXml;
    }

    public void setSchemaXml(String schemaXml) {
        this.schemaXml = schemaXml;
    }

    public String getDirectory() {
        return directory;
    }

    public void setDirectory(String directory) {
        this.directory = directory;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Long getCommitTime() {
        return commitTime;
    }

    public void setCommitTime(Long commitTime) {
        this.commitTime = commitTime;
    }

    public Long getUptime() {
        return uptime;
    }

    public void setUptime(Long uptime) {
        this.uptime = uptime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    public List<SolrCache> getCaches() {
        return caches;
    }

    public void setCaches(List<SolrCache> caches) {
        this.caches = caches;
    }

    public void addCache(SolrCache cache) {
        if (this.caches == null) {
            this.caches = new ArrayList<SolrCache>();
        }
        this.caches.add(cache);
    }
}